﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace HB.Expand
{
    /// <summary>
    /// 数字转其他类型
    /// </summary>
    public static class Number2Object
    {
        /// <summary>
        /// 转为文件大小 如  100M
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public static string ToFileSize(this long size)
        {
            string unit = "B";
            if (size > 1024)
            {
                size /= 1024;
                unit = "K";
            }
            if (size > 1024)
            {
                size /= 1024;
                unit = "M";
            }
            if (size > 1024)
            {
                size /= 1024;
                unit = "G";
            }
            if (size > 1024)
            {
                size /= 1024;
                unit = "T";
            }
            return $"{size.ToString("f2")}{unit}";
        }
        /// <summary>
        /// 转为文件大小 如  100M
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public static string ToFileSize(this int size)
        {
            return ToFileSize((long)size);
        }
    }
}
